﻿using System.Linq;
using Framework.Poco;
using Shell.DomainDot;

namespace Framework.Domain
{
    /// <summary>
    /// 文章更新器
    /// </summary>
    public class UpdateArticle : DomainDotBase<Category>
    {
        /// <summary>
        /// 指定分类的文章
        /// </summary>
        public WithMany<Article> Articles { get; set; }

        /// <summary>
        /// 更新文章
        /// </summary>
        public void Update(Article instance)
        {
            var original = this.Articles.SingleOrDefault(i => i.Id.Equals(instance.Id));
            if (original == null)
            {
                return;
            }            
            original.Name = instance.Name;
            original.Author = instance.Author;
            original.Breaks = instance.Breaks;
            original.Content = instance.Content;
            original.Hits = instance.Hits;
            original.IsTopmost = instance.IsTopmost;
            this.Articles.Submit();
        }
    }
}
